<template>
    <div class="home">
        <!-- 搜索框 -->
        <van-search
            placeholder="请输入搜索商品"
            shape="round"
            background="red"
            @click="goodsSearch"
        />
        <!-- tab标签分类 -->

        <van-tabs v-model:active="active" shrink>
            <van-tab v-for="item in list" :key="item.id" :title="item.name">
            </van-tab>
        </van-tabs>
        <!-- 轮播图 -->
        <van-swipe :autoplay="3000" lazy-render>
            <van-swipe-item v-for="item in bannerList" :key="item.id">
                <img :src="item.url" style="height: 200px; width: 100%" />
            </van-swipe-item>
        </van-swipe>
        <!-- 列表数据 -->
        <van-grid :column-num="2">
            <van-grid-item v-for="item in goodsList" :key="item.id">
                <van-image
                    width="8rem"
                    height="6rem"
                    fit="cover"
                    position="top"
                    :src="item.picture"
                    @click="toDetail(item)"
                />
                <span class="detail">{{ item.product }}</span>
                <div class="det">{{ item.detail }}</div>
                <div class="store">
                    <span class="price">￥239</span>
                    <span class="oldprice">￥988</span>
                </div>
            </van-grid-item>
        </van-grid>
    </div>
</template>

<script lang="ts" setup>
import { useCateogry, useBanner, useGoods, useSearch } from '@/hooks/home'
import { useToDetail } from '@/hooks/toDetail'
const { active, list } = useCateogry()
const { bannerList } = useBanner()
const { goodsList } = useGoods()
const { toDetail } = useToDetail()
const { goodsSearch } = useSearch()
</script>

<style scoped lang="scss">
.home{
    margin-bottom: 50px;
}
.my-swipe {
    .van-swipe-item {
        color: #fff;
        font-size: 20px;
        line-height: 150px;
        text-align: center;
        background-color: #39a9ed;
    }
}
.detail {
    width: 8rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 0.8rem;
}
.store {
    margin-top: 10px;
    font-size: 0.6rem;
    color: #ccc;
    .price {
        color: red;
        font-size: 0.8rem;
    }
    .oldprice {
        text-decoration: line-through;
    }
}
.det {
    width: 8rem;
    font-size: 0.6rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
</style>
